package com.journaldev.spring.model;

import java.sql.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

/**
 * Entity bean with JPA annotations
 * Hibernate provides JPA implementation
 * @author KhanhQuach
 *
 */
@Entity
@Table(name="benhnhan")
public class Patient {
	
	@Id
	@Column(name="id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	@Column(name="ho_ten")
	private String name;
	
	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Date getDateOfBirth() {
		return dateOfBirth;
	}


	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}


	@Column(name="nam_sinh")
	@DateTimeFormat(pattern = "dd/MM/yyyy")
	private Date dateOfBirth;
	
	@Column(name="sonha")
	private String address;


	public String getAddress() {
		return address;
	}


	public void setAddress(String address) {
		this.address = address;
	}


	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_xaphuong")
	private Ward belongToWard;


	public Ward getBelongToWard() {
		return belongToWard;
	}


	public void setBelongToWard(Ward belongToWard) {
		this.belongToWard = belongToWard;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_user")
	private UserInfo belongToDoctor;

	public UserInfo getBelongToDoctor() {
		return belongToDoctor;
	}


	public void setBelongToDoctor(UserInfo belongToDoctor) {
		this.belongToDoctor = belongToDoctor;
	}
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "belongToPatient", orphanRemoval = true)
	private Set<Prescription> prescriptionList;
	
	public Set<Prescription> getPrescription() {
		return prescriptionList;
	}

}
